import logging
from datetime import datetime
from uuid import uuid4
import base64

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)


# 生成随机任务ID
def gen_random_job_id(random_str_len=10):
    return datetime.now().strftime("%Y%m%d_%H%M%S") + "_" + uuid4().hex[:random_str_len]

def audio_to_base64(audio_path):
    with open(audio_path, "rb") as audio_file:
        return base64.b64encode(audio_file.read()).decode("utf-8")
    
def base64_to_audio_file(base64_string, output_path):
    audio_bytes = base64.b64decode(base64_string)
    with open(output_path, "wb") as f:
        f.write(audio_bytes)
    return output_path
